/**
rid: 118553
user: 04172604ZDY
time: 2017-11-26 12:44:38
result: Runtime Error 
*/
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

vector<vector<float> > T;
vector<short > aims;
vector<vector<float> > data;
float result;

float deal(short self, int aimCount) {
    if(data[self][aimCount-1] != -1)
        return data[self][aimCount-1];
    short aim = aims[aims.size()-aimCount];
    data[self][aimCount-1] = T[self][aim];
    if(aimCount > 1) {
        float orig = deal(self, aimCount - 1);
        float replace = deal(aim, aimCount - 1);
        data[self][aimCount - 1] *= (orig > replace ? orig : replace);
    }
    if(data[self][aimCount-1] < result)
        return 0;
    return data[self][aimCount-1];
}

int main() {
    int n;
    while(cin >> n) {
        int R = n*(n-1)*(n-2)/6;//max 120
        //init T
        T.resize(R);
        for(int i = 0; i < R; i++) {
            T[i].resize(R);
            for(int j = 0; j < R; j++) {
                cin >> T[i][j];
            }
        }
        //init aims
        int aimCount;
        cin >> aimCount;
        aims.resize(aimCount);
        for(int i = 0; i < aimCount; i++) {
            cin >> aims[i];
        }
        //init data
        data.clear();
        data.resize(R);
        for(int i = 0; i < R; i++) {
            data[i].clear();
            data[i].resize(aimCount, -1);
        }
        //deal with data
        result = 0;
        for(int i = 0; i < R; i++) {
            float cache = deal(i, aimCount);
            if(cache > result)
                result = cache;
        }
        cout << std::fixed << setprecision(6) << result << endl;
    }
    return 0;
}